package com.zy.openchat.core.model.message;

import android.os.Parcel;
import android.os.Parcelable;

public class TextEntity implements Parcelable {

    public int length;
    public int offset;
    public TextEntityType type;

    public TextEntity() {
    }

    public TextEntity(int length, int offset, long userId) {
        this.length = length;
        this.offset = offset;
        this.type = new TextEntityType(userId);
    }

    public TextEntity(int length, int offset, String type) {
        this.length = length;
        this.offset = offset;
        TextEntityType entityType = new TextEntityType();
        entityType.type = type;
        this.type = entityType;
    }




    public long userId(){
        if(type!=null){
            return type.user_id;
        }
        return 0;
    }

    public String topic(){
        if(type!=null){
            return type.url;
        }
        return null;
    }



    public long remittanceId(){
        if(type!=null){
            return type.remittanceId;
        }
        return 0;
    }


    public int start(){
        return offset;
    }

    public int end(){
        return offset+length;
    }



//    @Override
//    public String toString() {
//        return "{" +
//                "length=" + length +
//                ", offset=" + offset +
//                ", type=" + type.toString() +
//                '}';
//    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.length);
        dest.writeInt(this.offset);
        dest.writeParcelable(this.type, flags);
    }

    public void readFromParcel(Parcel source) {
        this.length = source.readInt();
        this.offset = source.readInt();
        this.type = source.readParcelable(TextEntityType.class.getClassLoader());
    }

    protected TextEntity(Parcel in) {
        this.length = in.readInt();
        this.offset = in.readInt();
        this.type = in.readParcelable(TextEntityType.class.getClassLoader());
    }

    public static final Creator<TextEntity> CREATOR = new Creator<TextEntity>() {
        @Override
        public TextEntity createFromParcel(Parcel source) {
            return new TextEntity(source);
        }

        @Override
        public TextEntity[] newArray(int size) {
            return new TextEntity[size];
        }
    };
}
